﻿using System;
using System.IO;

namespace Kryptecizer.Helpers
{
    class Filer
    {
        public static String readFromTxtFile(String fileName)
        {
            String text = String.Empty;

            try
            {
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader(fileName))
                {
                    String line;
                    // Read and display lines from the file until the end of 
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null)
                    {
                        text += line + Environment.NewLine;
                    }
                }
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                return null;
            }
            return text;
        }
        public static bool writeIntoFile(String fileName, String text)
        {
            try
            {
                using (StreamWriter sw = new StreamWriter("TestFile.txt"))
                {
                    // Add the text to the file.
                    sw.Write(text);
                    sw.Close();
                }
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }
    }
}
